'''
Created on 12.12.2009

@author: stud
'''
import vtk
from vtk.tk.vtkTkRenderWidget import *

class VTK(object):
    
    __numberOfBodies= None
    
    def __init__(self):  
        '''
        Starting new Renderer
        '''   
        self.__sphereList = []
        self.__ren = vtk.vtkRenderer()
        
    def startVTK(self, numberOfBodies, bodyList):
        '''
        Giving VTK with numberOfBodies and BodyList
        '''  
        self.__bodyList = bodyList     
        self.__numberOfBodies = numberOfBodies
        
    def setRadi(self):  
        '''
        Adding new Spheres and calling calcRadi for helping with Radi Size Setting
        ''' 
        for i in range(self.__numberOfBodies):
            sphere = vtk.vtkSphereSource()
            sphere.SetRadius(self.calcRadi(self.__bodyList[i].radius))
            sphere.SetPhiResolution(20)
            sphere.SetThetaResolution(20)
            sphereMapper = vtk.vtkPolyDataMapper()
            sphereMapper.SetInputConnection(sphere.GetOutputPort())
            sphereActor = vtk.vtkActor()
            sphereActor.SetMapper(sphereMapper)
            self.__ren.AddActor(sphereActor)
            self.__sphereList.append(sphereActor)
    
    def calcRadi(self, body):
        if body <= 10E6:
            return 10E6*4000
        elif (body >10E6) and (body < 10E8):
            return body *3000
        else:
            return 10E8 *3000    
    
    def startRenderer(self):
        '''
        Adding Cam, Light, Background to Renderer
        '''         
        self.__ren.SetBackground(0.1, 0.2, 0.4)
        light = vtk.vtkLight()
        light.SetPosition(- 200, - 200, 200)    # hier muss Zentralgesirn hin
        self.__ren.AddLight(light)
        cam = self.__ren.GetActiveCamera()
        cam.SetPosition(0, -10E12, 0)
        cam.SetFocalPoint(0, 0, 0)
        cam.SetViewUp(0, 0, 1)
        cam.SetViewAngle(20)
        cam.SetClippingRange(10E9, 10E14)
        self.__ren.SetActiveCamera(cam)
        self.__ren.ResetCamera()
        self.__ren.SetBackground(0.1, 0.2, 0.4)
    
    def getRenderer(self):
        return self.__ren
    
    def getSphereList(self):
        return self.__sphereList
            